import Cookies from 'js-cookie'


const UserToken = 'User_Token'
const UserNickName = 'User_NickName'
const UserId = 'User_Id'
const UserImg = 'User_img'


export function getUserImg() {
  return Cookies.get(UserImg)
}

export function setUserImg(userImg) {
  return Cookies.set(UserImg, userImg)
}

export function removeUserImg() {
  return Cookies.remove(UserImg)
}

export function getToken() {
  return Cookies.get(UserToken)
}

export function setToken(token) {
  return Cookies.set(UserToken, token)
}

export function removeToken() {
  return Cookies.remove(UserToken)
}

export function getUserId() {
  return Cookies.get(UserId)
}

export function setUserId(userId) {
  return Cookies.set(UserId, userId)
}

export function removeUserId() {
  return Cookies.remove(UserId)
}

export function getUserNickName() {
  return Cookies.get(UserNickName)
}

export function setUserNickName(userNickName) {
  return Cookies.set(UserNickName, userNickName)
}

export function removeUserNickName() {
  return Cookies.remove(userNickName)
}


export function checkResData(code, successFlag) {
  if (code === 200 && successFlag == true) {
    return true
  }
  return false
}


// 生成的消息id
export function getId() {
  return Date.now()
}


//清除所有cookie函数
export function clearAllCookie() {
  var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  if (keys) {
    for (var i = keys.length; i--;)
      document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
  }
}
